# encoding: UTF-8
 
class Admin::CarouselsController < ApplicationController

  before_filter :user_signed_in?
  
  def index
    @carousels = Carousel.all
    #@carousels = Carousel.find_all_by_status(0)
    set_seo_meta '焦点图管理'
  end

  def new
		@carousel = Carousel.new
    set_seo_meta '焦点图新增'
  end

  def create
    @carousel = Carousel.new(params[:carousel])
    if @carousel.save!
      redirect_to carousels_path, notice: '新增成功!'
    else
      redirect_referrer_or_default default
    end  
  end

  def edit
    @carousel = Carousel.find(params[:id]) 
    set_seo_meta '焦点图修改'
  end

  def update
    @carousel = Carousel.find(params[:id])
    if @carousel.update_attributes!(params[:session])
      redirect_to carousels_path, notice:'修改成功'
    else
      redirect_referrer_or_defautl default
    end
  end

  def destroy
    if Carousel.delete(params[:id])
      redirect_to carousels_path, notice:'删除成功'
    else
      redirect_referrer_or_default default
    end  
  end

end
